/***************
 * Organization Summary Panel
 */
AIR2.Organization.Summary = function() {
    return new AIR2.UI.Panel({
        colspan: 2,
        title: 'Organization Profile',
        iconCls: 'air2-icon-organization',
        storeData: AIR2.Organization.ORGDATA,
        url: AIR2.HOMEURL + '/organization',
        itemSelector: '.air2-org-info',
        tpl: new Ext.XTemplate(
            '<tpl for="."><div class="air2-org-info">' +
              '<table class="primary-info">' +
                '<tr>' +
                  '<td>' +
                    '<h1>{[AIR2.Format.orgNameLong(values)]}</h1>' +
                  '</td>' +
                  '<td rowspan="2">' +
                    '{[AIR2.Format.orgLogo(values, null, null, true)]}' +
                  '</td>' +
                '</tr>' +
                '<tr>' +
                  '<td>{[AIR2.Format.orgName(values)]}</td>' +
                '</tr>' +
              '</table>' +
              '<table class="meta">' +
                '<tr>' +
                  '<td><b>Status</b></td>' +
                  '<td>{[this.formatStatus(values.org_status)]}</td>' +
                '</tr>' +
                '<tpl if="parent"><tr>' +
                  '<td><b>Parent Organization</b></td>' +
                  '<td>{[AIR2.Format.orgNameLong(values.parent, true)]}</td>' +
                '</tr></tpl>' +
                '<tr>' +
                  '<td><b>Created by</b></td>' +
                  '<td>{[AIR2.Format.userName(values.CreUser, true)]} on {[AIR2.Format.date(values.org_cre_dtim)]}</td>' +
                '</tr>' +
              '</table>' +
            '</div></tpl>',
            {
                compiled: true,
                disableFormats: true,
                formatStatus: function(s) {
                    if (s == 'A') return 'Active';
                    else if (s == 'X') return 'Flagged for Deletion';
                    else if (s == 'F') return 'Inactive';
                    else return 'Unknown';
                }
            }
        ),
        allowEdit: AIR2.Organization.ORGDATA.authz.may_manage,
        editInPlace: [{
            xtype: 'container',
            layout:'column',
            items:[{
                xtype: 'container',
                columnWidth: .5,
                layout: 'form',
                style: 'padding-right:10px',
                items: [{
                    xtype: 'fieldset',
                    title: 'Information',
                    defaults: {msgTarget: 'under'},
                    items: [{
                        xtype: 'textfield',
                        fieldLabel: 'Name',
                        name: 'org_display_name'
                    },{
                        xtype: 'air2combo',
                        fieldLabel: 'Status',
                        name: 'org_status',
                        width: 100,
                        choices: [['A', 'Active'], ['F', 'Inactive']]
                    }]
                }]
            },{
                xtype: 'container',
                columnWidth: .5,
                layout: 'form',
                items: [{
                    xtype: 'fieldset',
                    title: 'Display',
                    defaults: {msgTarget: 'under'},
                    items: [{
                        xtype: 'textfield',
                        fieldLabel: 'Short Name',
                        name: 'org_name'
                    },{
                        xtype: 'trigger',
                        fieldLabel: 'Hex Color',
                        name: 'org_html_color',
                        onTriggerClick: function(e) {
                            var fld = this;
                            var menu = new Ext.menu.ColorMenu({
                                handler: function(cm, color){
                                    fld.setValue(color);
                                }
                            });
                            menu.show(fld.el, 'tl-bl?');
                        }
                    },{
                        xtype: 'textfield',
                        fieldLabel: 'Logo Url',
                        name: 'org_logo_uri',
                        vtype: 'url'
                    }]
                }]
            }]
        }]
    });
}
